<?php
// File: app/controllers/customers_controller.php
class CustomersController extends AppController
{
	var $name = 'Customers';
	var $helpers = array ('Html','Form');
	var $components = array('Session');
	
	function new_customer()
	{
		return $this->Customer->find("all",array(
					'limit' => 5,
					'order' => array('customer_id' => 'desc'),
		));
	}
	
	function index()
	{
		$this->paginate=array
		(
			'limit' => 10,
			'order' => array('customer_id' => 'asc'),
		);
		$data = $this->paginate("Customer");
		$this->set("customers",$data);
	}
	
	function view_detail($id=null)
	{
		$this->Customer->customer_id = $id;
		$this->set('customer', $this->Customer->read());
	}
	
	function add() {
		if (!empty($this->data)) {
			$this->data['Customer']['create_date'] = DboSource::expression('NOW()');
			if(isset($_POST['create'])){
				if ($this->Customer->save($this->data)) {
					$this->Session->setFlash('Your customer has been saved.');
					$this->redirect(array('action' => 'index'));
				}
			}
			if(isset($_POST['create_continue'])){
				if ($this->Customer->save($this->data)) {
					$this->Session->setFlash('Your customer has been saved.');
					$this->redirect(array('action' => 'add'));
				}
			}
		}
	}
	
	function delete($id) {
		if ($this->Customer->delete($id))
		{
			$this->Session->setFlash('The customer with id: ' .$id . ' has been deleted.');
			$this->redirect(array('action' => 'index'));
		}
	}
	

	function edit($id = null) {
		$this->Customer->id = $id;
			
		if (empty($this->data)) {
			$this->data = $this->Customer->read();
		} else {
			$this->data['Customer']['update_date'] = DboSource::expression('NOW()');
			if ($this->Customer->save($this->data)) {
				$this->Session->setFlash('Your customer has been updated.');
				$this->redirect(array('action' => 'index'));
			}
		}
	}
}
?>